<%@page import="entityBeans.ContactGroup"%>
<%@page import="entityBeans.Enterprise"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="entityBeans.Contact" %>
    <%@ page import="entityBeans.PhoneNumber" %>
    <%@ page import="java.util.List" %>
    <%@ page import="java.util.ArrayList" %>
    <%@ page import="java.util.Set" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" media="screen, projection" href="scripts/demo.css" />
<script type="text/javascript" src="scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="scripts/validation.js"></script>
<title>Modification Contact</title>
</head>
<body>
	<% Contact contact = (Contact)request.getAttribute("contact");
		PhoneNumber p1 = (PhoneNumber)contact.getPhones().toArray()[0];
		PhoneNumber p2 = (PhoneNumber)contact.getPhones().toArray()[1];
		PhoneNumber p3 = (PhoneNumber)contact.getPhones().toArray()[2];
	%>
	<form action="EditContact" method="post" onsubmit="return validateFormAdd()">
	<br><br>
	<table align="center" bgcolor="green" id="containerAddContact">
	<tr><td align="right">Groups : </td><td width="200"><select multiple="multiple" name="groups">
	<% List<ContactGroup> listGroups = (List<ContactGroup>)request.getAttribute("listGroup");
	List<ContactGroup> groups = (List<ContactGroup>)request.getAttribute("groups");
	List<String> cgList = new ArrayList<String>();
	for(ContactGroup cg : groups){
		cgList.add(cg.getGroupName());
	}
	if (listGroups != null && listGroups.size() > 0){ %>
	
	<%for(ContactGroup g : listGroups){
		if(cgList.contains(g.getGroupName())){
	%>
		<option value="<%=g.getGroupName()%>" selected="selected"><%=g.getGroupName()%></option>
	<%} else{%>
		<option value="<%=g.getGroupName()%>"><%=g.getGroupName()%></option>
	<%}}}%>
	</select></td>
	</tr>
	<tr>
	<td>Other group </td><td><input type="text" name="other"/> </td>
	</tr>
	<tr>
		<td align="right">First name* : </td><td><input type="text" id="firstname" name="firstname" value="<%=contact.getFirstName()%>"></td><td><label id="lbCheckFirstName" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Last name* : </td><td><input type="text" id="lastname" name="lastname" value="<%=contact.getLastName()%>"></td><td><label id="lbCheckLastName" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Email* : </td><td><input type="text" id="email" name="email" value="<%=contact.getEmail()%>"></td><td><label id="lbCheckEmail" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Street* : </td><td><input type="text" id="street" name="street" value="<%=contact.getAddress().getStreet()%>"></td><td><label id="lbCheckStreet" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">City* : </td><td><input type="text" id="city" name="city" value="<%=contact.getAddress().getCity()%>"></td><td><label id="lbCheckCity" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Zip code* : </td><td><input type="text" id="zip" name="zip" value="<%=contact.getAddress().getZip()%>"></td><td><label id="lbCheckZip" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Telephone* : </td><td><input type="text" id="phone1" name="phone1" value="<%=p1.getPhoneNumber()%>">
		<select id="phonetype1" name="phonetype1">
		<%if(p1.getPhoneKind().equals("Mobile")){ %>
		<option value="Mobile" selected="selected">Mobile</option>
    	<option value="Fix">Fix</option>
    	<%}else{ %>
    	<option value="Mobile">Mobile</option>
    	<option value="Fix" selected="selected">Fix</option>
    	<%} %>
		</select></td>
		<td><label id="lbCheckPhone1" style="color: red;"></label></td>
	</tr>
	<tr>
		<td></td><td><input type="text" id="phone2" name="phone2" value="<%=p2.getPhoneNumber()%>">
		<select id="phonetype2" name="phonetype2">
		<%if(p2.getPhoneKind().equals("Mobile")){ %>
		<option value="Mobile" selected="selected">Mobile</option>
    	<option value="Fix">Fix</option>
    	<%}else{ %>
    	<option value="Mobile">Mobile</option>
    	<option value="Fix" selected="selected">Fix</option>
    	<%} %>
		</select></td>
	</tr>
	<tr>
		<td></td><td><input type="text" id="phone3" name="phone3" value="<%=p3.getPhoneNumber()%>">
		<select id="phonetype3" name="phonetype3">
		<%if(p3.getPhoneKind().equals("Mobile")){ %>
		<option value="Mobile" selected="selected">Mobile</option>
    	<option value="Fix">Fix</option>
    	<%}else{ %>
    	<option value="Mobile">Mobile</option>
    	<option value="Fix" selected="selected">Fix</option>
    	<%} %>
		</select></td>
	</tr>
	<%if(contact instanceof Enterprise){%>
	<tr>
		<td align="right" id="lbsiret">SIRET Number* : </td>
		<td><input type="text" id="siret" name="siret" value="<%=((Enterprise)contact).getNumSiret()%>"></td>
	</tr>
	<%} %>
	<tr>
		<td></td><td><input type="submit" value="Update">  <input type="reset" value="Reset"></td>
	</tr>
	
	</table> 
	</form>
</body>
</html>